clear all; clc; close all
j = 0;
Fd = 44.2e6;
  Bw = 2*pi*4e6;
  w0= 2*pi*10e6;
 
for n = [3]
    j = j + 1;
    [z, p, k] = buttap(n);
    [b, a] = zp2tf(z, p, k);

  
    [b_new, a_new] = lp2bp(b, a, w0, Bw);
    [bd,ad]=bilinear(b_new,a_new,Fd);
    [Hn, wn] = freqs(bd, ad); 
    
    H(:, j) = Hn; 
    w(:, j) = wn;
end


figure(1)
plot(w, abs(H))
xlabel('\omega, rad/s');
ylabel('|H(j\omega)|');
% legend('n=1','n=3','n=5');
legend('n=5');
grid on






 Td = 1/Fd;
tmax = 0.001; t = 0:Td:tmax;
N_PRN = 511; T_PRN = 0.001;
PRN = sign(randn(1, N_PRN));
ind_h = fix(mod(t/T_PRN, 1)*N_PRN) + 1;
h = PRN(ind_h);
A = 2;
f0 = 10e6;
phi = pi/4;
u = A * h .* cos(2*pi*f0*t + phi);
FM = ifft(u); 
figure(2)
subplot(2,1,1)
plot(1:length(FM),abs(FM)) 
y = filter(bd, ad, u);

Fy=ifft(y);

subplot(2,1,2)
plot(1:length(Fy), abs(Fy))
